package cn.lavender.web.async;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;

/**
 * <p>
 *
 * @Async 使用示例
 * </p>
 * @author: zhu.chen
 * @date: 2021/3/22
 * @version: v1.0.0
 */
@Service
public class AsyncServiceTest {

    @Autowired
    private AsyncTaskExecutor asyncThreadPoolExecutor;

    /**
     * @Async 无返回值
     */
    @Async(value = "asyncThreadPoolExecutor")
    public void test() {
        return;
    }

    /**
     * 有返回值
     * @return
     */
    @Async(value = "asyncThreadPoolExecutor")
    public Future<String> hello() {
        return new AsyncResult<>("ok");
    }

}
